package org.black.phoneUtility.sms.schedule.app.fragment;

import org.black.phoneUtility.R;
import org.black.phoneUtility.app.TabsFragmentPagerAdapter;

import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.TabHost;

public class SmsScheduleFragment extends Fragment {
	public static final String TAG = SmsScheduleFragment.class.getName();
	TabHost tabHost;
	ViewPager viewPager;
	TabsFragmentPagerAdapter tabsFragmentPagerAdapter;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		getActivity().setTitle(getString(R.string.sms_schedule_title));
		View result = inflater.inflate(R.layout.sms_schedule_main, container,
				false);
		tabHost = (TabHost) result.findViewById(R.id.smsScheduleMainTabHost);
		tabHost.setup();
		HorizontalScrollView hrizontalScrollView = (HorizontalScrollView) result
				.findViewById(R.id.smsScheduleMainTabWidgetHorizontalScrollView);

		viewPager = (ViewPager) result
				.findViewById(R.id.smsScheduleMainViewPager);

		this.tabsFragmentPagerAdapter = new TabsFragmentPagerAdapter(
				getActivity(), getChildFragmentManager(), tabHost,
				hrizontalScrollView, viewPager);

		this.tabsFragmentPagerAdapter
				.addTab(tabHost
						.newTabSpec(SmsScheduleListFragment.TAG)
						.setIndicator(
								getString(R.string.sms_schedule_tab_indicator_setting)),
						SmsScheduleListFragment.class, null);
		this.tabsFragmentPagerAdapter
				.addTab(tabHost
						.newTabSpec(
								SmsScheduleSendingRecordRecipientsHistoryListFragment.TAG)
						.setIndicator(
								getString(R.string.sms_schedule_tab_indicator_history)),
						SmsScheduleSendingRecordRecipientsHistoryListFragment.class,
						null);

		if (savedInstanceState != null) {
			tabHost.setCurrentTabByTag(savedInstanceState
					.getString(SmsScheduleListFragment.TAG));
		}
		setHasOptionsMenu(true);
		return result;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_sms_schedule_settings:

			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
		// TODO Auto-generated method stub
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		this.tabHost = null;
		this.viewPager = null;
		this.tabsFragmentPagerAdapter = null;
	}

	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		super.onCreateOptionsMenu(menu, inflater);
		// inflater.inflate(R.menu.sms_schedule_actions, menu);
	}

}
